package com.wecan.components.pay.config;

import com.wecan.components.pay.controller.PayController;
import com.wecan.components.pay.properties.WxPayProperties;
import com.wecan.components.pay.service.PayService;
import com.wecan.components.pay.service.ProcessOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @Author liuzhihao
 * @Date 2022.02.22
 * @Version ${version}
 * @Description ${description}
 */
@Configuration
@EnableConfigurationProperties({WxPayProperties.class})
@Slf4j
public class PayConfig {

    @PostConstruct
    public void postConstruct() {
        log.info("[APP] |- 初始化APP支付服务");
    }

    @Bean
    public PayService payService() {
        return new PayService();
    }

    @Bean
    public ProcessOrderService processOrderService() {
        return new ProcessOrderService();
    }

    @Bean
    @ConditionalOnBean(PayService.class)
    public PayController payController() {
        log.info("[APP] |- 初始化支付web服务");
        return new PayController();
    }
}
